home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
-
- FICHERO: ERROR.C
-
- AUTOR: ANTONIO LADESA JURADO
-
- FECHA: 24/6/94
-
- DESCRIPCION:
-
- Fichero que contiene las estructuras, constantes, variables y funciones
- internas y externas para el manejo de errores
-
- ==============================================================================*/
-
-
- /*---- MODULOS USADOS --------------------------------------------------------*/
-
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include <dir.h>
-
- #include "error.h"
- #include "menu.h"
- #include "teclas.h"
- #include "raton.h"
-
- /*---- ESTRUCTURAS, CONSTANTES Y VARIABLES LOCALES AL MODULO -----------------*/
-
- /* respuestas al error hardware */
- #define IGNORAR 0
- #define REINTENTAR 1
- #define ANULAR 2
-
- /* error software actual */
- static ERROR ERRORsoftware;
-
- /* definicion de los mensajes de error para atrapar problemas de disco */
- static char *errores_hardware[] =
- {
- "Disco protegido",
- "Unidad desconocida",
- "Unidad no preparada",
- "Comando desconocido",
- "Error de datos (CRC)",
- "Respuesta erronea",
- "Error de posicion",
- "Medio desconocido",
- "Sector no encontrado",
- "Impresora sin papel",
- "Error de escritura",
- "Error de lectura",
- "Fallo general",
- "Reservado",
- "Reservado",
- "Cambio de disco erroneo"
- };
-
- /* definición de los mensajes de error dados por el programa */
- static char *errores_software[] =
- {
- "",
- "No hay imagen cargada",
- "No hay memoria",
- "Leyendo fichero",
- "Escribiendo fichero",
- "Abriendo fichero",
- "Formato no tratado",
- "Formatos incompatibles",
- "La imagen es monocromatica",
- "La imagen no es monocromatica",
- "Imagen demasiado grande",
- "Imposible escalar más",
- "Impresora no preparada",
- "Imposible borrar fichero",
- "Imposible renombrar fichero",
- "Ratón no instalado",
- };
-
- /*---- DEFINICION DE LAS FUNCIONES INTERNAS ----------------------------------*/
-
- int leer_respuesta(char *msg);
- int manejador(int errval,int ax,int bp,int si);
-
- /*---- CODIFICACION DE LAS FUNCIONES OFRECIDAS -------------------------------*/
-
- /*---- FUNCION: extern void ERRORmanejador(void) -------------------------------
-
- Descripción:
-
- Esta función instala el manejador de errores de hardware para
- tratar errores del disco, fundamentalmente
-
- ---- CODIGO: -----------------------------------------------------------------*/
-
- extern void ERRORmanejador(void)
- {
- harderr(manejador);
- }
-
- /*---- FIN FUNCION -----------------------------------------------------------*/
-
- /*---- FUNCION: extern int ERRORponer(int error) -------------------------------
-
- Descripción:
-
- Esta función establece un error del programa, actualizando la variable
- ERRORsoftware
-
- Parámetros:
-
- int error: código de error
-
- Retorno:
-
- Código del error
-
- ---- CODIGO: -----------------------------------------------------------------*/
-
- extern int ERRORponer(int error)
- {
- return(ERRORsoftware = error);
- }
-
- /*---- FIN FUNCION -----------------------------------------------------------*/
-
- /*---- FUNCION: extern int ERRORver(void) --------------------------------------
-
- Descripción:
-
- Esta función visualiza un error y lo elimina tras la lectura de un
- evento
-
- Retorno:
-
- ERRno
-
- ---- CODIGO: -----------------------------------------------------------------*/
-
- extern int ERRORver(void)
- {
- char msg[128];
- struct EVENTO evento;
- if(ERRORsoftware)
- {
- sprintf(msg,"Error:%s",errores_software[ERRORsoftware]);
- putch(7);
- ESTADOponer(msg);
- do
- {
- evento = leer_evento(evento);
- }
- while(evento.e == NO_EVENTO);
- ESTADOquitar();
- }
- return(ERRORsoftware = ERRno);
- }
-
- /*---- FIN FUNCION -----------------------------------------------------------*/
-
- /*---- CODIFICACION DE LAS FUNCIONES INTERNAS --------------------------------*/
-
- /*---- FUNCION: int leer_respuesta(char *msg) ----------------------------------
-
- Descripción:
-
- Esta función lee una respuesta ante un error de dispositivo
-
- Parámetros:
-
- char *msg: mensaje de error
-
- Retorno:
-
- Respuesta: ANULAR, REINTENTAR o IGNORAR
-
- ---- CODIGO: -----------------------------------------------------------------*/
-
- int leer_respuesta(char *msg)
- {
- int respuesta;
- struct EVENTO evento;
-
- ESTADOponer(msg);
-
- /* lectura de tecla para (a)bortar, (r)eintentar o (i)gnorar */
- while(1)
- {
- evento = leer_evento(evento);
- ESTADOquitar();
-
- if(evento.e == RATON_IZDO_ON)
- {
- respuesta = REINTENTAR;break;
- }
- else if(evento.e == RATON_DCHO_ON)
- {
- respuesta = IGNORAR;break;
- }
-
- respuesta = evento.e;
-
- if (respuesta == 'a' || respuesta == 'A')
- {
- respuesta = ANULAR;break;
- }
- if (respuesta == 'r' || respuesta == 'R')
- {
- respuesta = REINTENTAR;break;
- }
- if (respuesta == 'i' || respuesta == 'I')
- {
- respuesta = IGNORAR;break;
- }
- }
- return(respuesta);
- }
-
- /*---- FIN FUNCION -----------------------------------------------------------*/
-
- /*---- FUNCION: int manejador(int errval,int ax,int bp,int si) -----------------
-
- Descripción:
-
- Esta función es el manejador de errores de hardware para
- tratar errores del disco, fundamentalmente
-
- Parámetros:
-
- int errval : código del error
-
- int ax :
- int bp :
- int si : registros del procesador implicados
-
- ---- CODIGO: -----------------------------------------------------------------*/
-
- int manejador(int errval,int ax,int bp,int si)
- {
- static char msg[128];
- unsigned di;
- int drive;
- int errorno;
-
- di= _DI;
-
- /* Si no es un error de disco... */
- if(ax < 0)
- {
- leer_respuesta("Error de dispositivo");
- hardretn(ANULAR);
- }
-
- /* Si es error de disco */
- drive = ax & 0x00FF;
- errorno = di & 0x00FF;
- sprintf(msg,"Error: %s en unidad %c. A)bortar, R)eintentar, I)gnorar: ",
- errores_hardware[errorno], 'A' + drive);
-
- /* retorna al programa por la interrupcion 0x23 con abortar, reintentar,
- o ignorar segun responda del usuario. */
- hardresume(leer_respuesta(msg));
- return ANULAR;
- }
-
- /*---- FIN FUNCION -----------------------------------------------------------*/
-